<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>ESMS</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="/ssm_esms/static/css/font.css">
    <link rel="stylesheet" href="/ssm_esms/static/css/xadmin.css">
    <script type="text/javascript" src="/ssm_esms/static/js/jquery-3.3.1.js"></script>
    <script type="text/javascript" src="/ssm_esms/static/lib/layui/layui.js"></script>
    <script type="text/javascript" src="/ssm_esms/static/js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
      <!--<script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>-->
    <!--<script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>-->
    <![endif]-->
</head>

<body>
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a >首页</a>
        <a >岗位管理</a>
        <a>
          <cite>添加岗位</cite></a>
      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>

<div class="x-body layui-anim layui-anim-up">
    <form class="layui-form" action="">
        <div class="layui-form-item">
            <label class="layui-form-label">岗位名称</label>
            <div class="layui-input-block">
                <input name="p_name" lay-verify="pNameVerify" autocomplete="off" placeholder="请输入岗位名称" class="layui-input" type="text">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">岗位描述</label>
            <div class="layui-input-block">
                <input name="p_duty" lay-verify="pDutyrkVerify" autocomplete="off" placeholder="请输入岗位描述" class="layui-input" type="text">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">岗位补贴</label>
            <div class="layui-input-block">
                <input name="p_post_pay" lay-verify="pPostPayVerify" autocomplete="off" placeholder="请输入岗位补贴" class="layui-input" type="text">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="" lay-filter="demo1">添加</button>
            </div>
        </div>
    </form>
</div>
<script>

    layui.use(['form', 'layedit', 'laydate'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate;
        //自定义验证规则
        form.verify({
            pNameVerify: function(value){
                // 验证特殊字符
                var pattern = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>/?~！@#￥……&*（）——|{}【】‘；：”“'。，、？]");

                value = value.replace(" ","");
                if(value.length == 0){
                    return '岗位名称不能为空';
                }
                if(value.length > 200){
                    return '岗位名称过长';
                }
                if(pattern.test(value)){
                    return '岗位名称不能包含特殊字符';
                }
            },
            pDutyrkVerify: function(value){
                // 验证特殊字符
                var pattern = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>/?~！@#￥……&*（）——|{}【】‘；：”“'。，、？]");
                value = value.replace(" ","");
                if(value.length == 0){
                    return '岗位描述不能为空';
                }
                if(value.length > 200){
                    return '岗位描述过长';
                }
                // if(pattern.test(value)){
                //     return '岗位描述不能包含特殊字符';
                // }
            },
            pPostPayVerify: function(value){
                // 验证特殊字符
                var pattern = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>/?~！@#￥……&*（）——|{}【】‘；：”“'。，、？]");
                value = value.replace(" ","");
                if(value.length == 0){
                    return '岗位补贴不能为空';
                }
                if(!value.match("[0-9]+")) {
                    return '岗位补贴只能为数字';
                }
                if(value.length > 6){
                    return '岗位补贴过大';
                }
                if(parseFloat(value) < 0) {
                    return '岗位补贴不能为负数';
                }
            }

        });


        // 监听提交
        form.on('submit(demo1)', function(data){
            var p_post_pay = parseFloat(data.field.p_post_pay).toFixed(2);
            console.log(parseFloat(data.field.p_post_pay).toFixed(2));
            $.ajax({
                type:'post',
                url:'position/add.do',
                data: {"p_name":data.field.p_name.replace(" ",""), "p_duty":data.field.p_duty,"p_post_pay":p_post_pay},
                dataType:'json',
                success:function(data){
                    // 说明存在同名
                    if(data != 0) {
                        // console.log(data);
                        layer.msg("岗位名称已存在",{icon: 5,anim: 6});
                    } else {
                        // console.log(data);
                        layer.alert("添加成功", {
                                title: '添加信息'
                            },

                            function () {
                                window.parent.location.reload();
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(index);
                            }
                        );
                    }
                }

            });
            return false;
        });
    });
</script>

</body>

</html>